﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace DanhMuc
{
    class BangCapInfo
    {
        string _BangCapID;

        public string BangCapID
        {
            get { return _BangCapID; }
            set { _BangCapID = value; }
        }
        string _TenBangCap;

        public string TenBangCap
        {
            get { return _TenBangCap; }
            set { _TenBangCap = value; }
        }
        bool _Active;

        public bool Active
        {
            get { return _Active; }
            set { _Active = value; }
        }


    }
    class BangCapCtr
    {
        string StrCnn = ConfigurationManager.ConnectionStrings["HRMCNN"].ToString();
        public void Insert(BangCapInfo Item)
        {
            SqlParameter[] Param = new SqlParameter[]{
                new SqlParameter("BangCapID",DbType.String),
                new SqlParameter("TenBangCap",DbType.String),
                new SqlParameter("Active",DbType.Boolean)
            };
            Param[0].Value = Item.BangCapID;
            Param[1].Value = Item.TenBangCap;
            Param[2].Value = true;
            try
            {
                SqlHelper.ExecuteNonQuery(StrCnn, CommandType.StoredProcedure, "D_BangCap_Insert", Param);
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
            
        }
        public void Update(BangCapInfo Item)
        {
            SqlParameter[] Param = new SqlParameter[]{
                new SqlParameter("BangCapID",DbType.String),
                new SqlParameter("TenBangCap",DbType.String),
                new SqlParameter("Active",DbType.Boolean)
            };
            Param[0].Value = Item.BangCapID;
            Param[1].Value = Item.TenBangCap;
            Param[2].Value = true;
            try
            {
                SqlHelper.ExecuteNonQuery(StrCnn, CommandType.StoredProcedure, "D_BangCap_Update", Param);
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public void Delete(string strBangCapID)
        {
            SqlParameter[] Param = new SqlParameter[]{
                new SqlParameter("BangCapID",DbType.String)
            };
            Param[0].Value = strBangCapID;
            try
            {
                SqlHelper.ExecuteNonQuery(StrCnn, CommandType.StoredProcedure, "D_BangCap_Delete", Param);
            }
            catch (Exception ex)
            {
                throw ex;
            }        
        }
        public DataTable GetList()
        {
            DataSet Ds= SqlHelper.ExecuteDataset(StrCnn, CommandType.StoredProcedure, "D_BangCap_GetList");
            return Ds.Tables[0];

        }
        public BangCapInfo GetByID(string BangCapID)
        {
            SqlDataReader MyReader = SqlHelper.ExecuteReader(StrCnn, CommandType.StoredProcedure, "D_BangCap_Get", new SqlParameter("BangCapID", BangCapID));
            BangCapInfo ReturnObject = null;
            while (MyReader.Read())
            {
                ReturnObject = new BangCapInfo();
                ReturnObject.BangCapID = MyReader["BangCapID"].ToString();
                ReturnObject.TenBangCap = MyReader["TenBangCap"].ToString();
                ReturnObject.Active =(bool) MyReader["Active"];
            }
            return ReturnObject;
        }
    }
}
